package cn.tedu.rabbitmq.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SendController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    //测试接口/send
    @GetMapping("/send")
    public String send(String msg){
        //将参数msg 组织成消息发送到rabbitmq 等待消费者监听消费
        //convertAndSend 可以将任意消息体数据对象(只要对象类型实现了序列化接口) 发送到指定交换机
        //channel.basicPublish(交换机名称,路由key,消息序列化数组)
        rabbitTemplate.convertAndSend("demo-ex","demo-rk",msg);
        return "发送成功";
    }
}
